package kr.saeildamil.androidstudy_second.br_service;

import kr.saeildamil.andrordstudy.second.R;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class NapAlarm extends Activity {
	static final int NAPNOTI=1;
	NotificationManager mNotiManager;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch2930_napalarm);
		mNotiManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
	}
	
	public void mOnClick(View v){
		Toast.makeText(this, "안녕히 주무세요", Toast.LENGTH_LONG).show();
		v.postDelayed(new Runnable() {
			public void run() {
				Intent intent = new Intent(NapAlarm.this, NapEnd.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				PendingIntent content = PendingIntent.getActivity(NapAlarm.this, 0, intent, 0);
				
				Notification.Builder noti = new Notification.Builder(NapAlarm.this)
				.setTicker("일어나세요")
				.setContentTitle("기상 시간")
				.setContentText("일어나! 일할 시간이야")
				.setSmallIcon(R.drawable.mugung)
				.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.korandoc))
				.setContentIntent(content);
				
				mNotiManager.notify(NAPNOTI, noti.getNotification());
			}
		}, 5*1000);
	}
}
